package com.ygo.feihua;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v4.util.ArrayMap;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.DownloadFileListener;
import cn.bmob.v3.listener.FindListener;
import com.baidu.mapapi.radar.RadarNearbyInfo;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.SimpleTarget;
import com.ygo.feihua.BmobTable.GuangGao;
import com.ygo.feihua.BmobTable.GxWz;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import java.io.BufferedOutputStream;
import com.file.zip.ZipFile;
import com.file.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ProgressBar;
import android.widget.Adapter;
import com.ygo.feihua.adapter.AdapterTextview;
import com.ygo.feihua.BmobTable.*;
import cn.bmob.v3.*;
import javax.net.ssl.*;
import android.annotation.*;
import java.security.cert.*;
import java.net.*;
import java.io.*;
import android.widget.*;
import android.content.*;
import android.app.*;
import android.view.*;
import android.util.*;
import android.view.inputmethod.*;
import android.graphics.*;
import cn.bmob.v3.listener.*;
import cn.bmob.v3.datatype.*;
import com.ygo.feihua.Management.*;
import com.ygo.feihua.logo.*;
import com.ygo.feihua.util.*;
import java.lang.ref.*;
import java.util.*;
import java.util.concurrent.*;
import android.os.AsyncTask;
import com.bumptech.glide.request.*;
import com.yuyh.library.imgsel.*;
import com.yuyh.library.imgsel.common.*;
import com.yuyh.library.imgsel.config.*;
import org.json.*;
import com.qnw.CardGroupManagement.*;
import com.pgyersdk.update.*;
import com.pgyersdk.javabean.*;


public class Gongju{
	private Context context;
	
	//ygomobile默认路径
    public static final String PATH_MOBILE=Environment.getExternalStorageDirectory().toString()+"/ygocore/";
	//根目录
	public static final String PATH_GEN=Environment.getExternalStorageDirectory().toString()+"/";
	//我们的游戏王默认路径
	public static final String PATH_OURYGO=Environment.getExternalStorageDirectory().toString()+"/ygo助手/";
	//卡组管理默认路径
	public static final String PATH_EZ_MANAGEMENT=Environment.getExternalStorageDirectory().toString()+"/ygo助手/Cardgroup_Management/";
	//决斗版本
	public static final String DUEL_VERSION="1";
	public static final String URL_YGO233_CARD_DIALOGUES="https://raw.githubusercontent.com/mercury233/mercury233.github.io/master/ygosrv233/dialogues.json";
	
	private static List<Gongju> contexts=new ArrayList<Gongju>();
	
	
	public static final int ZHUTI_VERCODE=2;
	
	//主题包
	public static final String[] ZHUTI_TEXTURES={
		"act.png",
		"attack.png",
		"bg.jpg",
		"bg_menu.jpg",
		"bg_deck.jpg",
		"chain.png",
		"chaintarget.png",
		"cover.jpg",
		"cover2.jpg",
		"equip.png",
		"extra/lscale_0.png",
		"extra/lscale_1.png",
		"extra/lscale_10.png",
		"extra/lscale_11.png",
		"extra/lscale_12.png",
		"extra/lscale_13.png",
		"extra/lscale_2.png",
		"extra/lscale_3.png",
		"extra/lscale_4.png",
		"extra/lscale_5.png",
		"extra/lscale_6.png",
		"extra/lscale_7.png",
		"extra/lscale_8.png",
		"extra/lscale_9.png",
		"extra/rscale_0.png",
		"extra/rscale_1.png",
		"extra/rscale_10.png",
		"extra/rscale_11.png",
		"extra/rscale_12.png",
		"extra/rscale_13.png",
		"extra/rscale_2.png",
		"extra/rscale_3.png",
		"extra/rscale_4.png",
		"extra/rscale_5.png",
		"extra/rscale_6.png",
		"extra/rscale_7.png",
		"extra/rscale_8.png",
		"extra/rscale_9.png",
		"extra/",
		"f1.jpg",
		"f2.jpg",
		"f3.jpg",
		"field-transparent2.png",
		"field-transparent3.png",
		"field2.png",
		"field3.png",
		"lim.png",
		"lp.png",
		"lpf.png",
		"mask.png",
		"negated.png",
		"number.png",
		"ot.png",
		"target.png",
		"unknown.jpg",
		};
		
	private DialogUtils dus;

	public static String URL_DOWNLOAD_XYSE="http://pan.baidu.com/s/1mhPmOOS";

	public void checkLogin(Context context,Class<?> cls)
	{
		if(isLogin(context)){
			context.startActivity(new Intent(context,cls));
		}
		
		// TODO: Implement this method
	}

	
	public boolean isLogin(Context context){
		UserManagement um=UserManagement.getDx();
		if(um.getUser()!=null){
			return true;
		}else{
			show("还没登录喵~");
			um.logInUser(context);
			return false;
		}
	}
	
	/*public static String getDqTime(){
	return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
	
	}*/

	public Context getContext()
	{
		return context;
	}
		
	//获取该类对象
	public static Gongju getdx(Context context){
		Gongju gj1=getGj(context);
		
		if(gj1 !=null){
			return gj1;
		}else{
			Gongju gj=new Gongju(context);
			contexts.add(gj);
			return gj;
		}
	}
	
	private static Gongju getGj(Context con){
		for( Gongju du:contexts){
			if(du.getContext().equals(con)){
				return du;
			}
		}
		return null;
	}
	
	private Gongju(Context context){
		this.context=context;
		dus=DialogUtils.getdx(context);
		
	}


	private static final List<Map<String,Object>> updaterz=new ArrayList<Map<String,Object>>();
	public static final List<Map<String,Object>> getupdaterz(){
	if(updaterz.size()==0){
		Map<String,Object> ma;
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.2.01");
		ma.put("message","修复帖子评论失败的bug\n其他优化");
		updaterz.add(ma);	


	
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.2.0");
		ma.put("message","部分界面优化\n可直接使用qq扫描卡组二维码查看卡组\n接入MiPush\n修复部分bug\n其他优化");
		updaterz.add(ma);	
		
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.1.32");
		ma.put("message","修复一些bug\n其他优化");
		updaterz.add(ma);	
		
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.1.31");
		ma.put("message","修复一些bug\n其他优化");
		updaterz.add(ma);	
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.1.3");
		ma.put("message","去除地图导航\n社区发帖新增板块\n修复残局编辑的各种bug\n其他优化");
		updaterz.add(ma);	
		
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.1.1");
		ma.put("message","修复卡表崩溃的bug\n修复数据库管理中移动和复制卡片无反应的bug\n去除\"决斗\"功能\n其他优化");
		updaterz.add(ma);	
		
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.1.0");
		ma.put("message","各种地方新增对link卡的支持\n新增卡片查询\n数据库编辑可对多数据库进行编辑\n可对压缩包内卡图进行删除\n其他优化");
		updaterz.add(ma);	
			
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•2.0.0");
		ma.put("message","布局优化\n新增无卡面基(YGORoid)\n新增机器人小废\n群聊新增卡片引用(输入格式[kp卡密],如[kp58481572])\n新增卡片combo,卡片召唤词,卡片资料\n支持读取压缩包内卡图\n去除聊天表情\n其他优化");
		updaterz.add(ma);
			
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•1.3.0");
		ma.put("message","我们的游戏王与YGO EZ Manager合并\n决斗版本更新至1\n新增二维码分享卡组\n默认替换卡表更新至2017.1.1 OCG禁卡表\n其他优化");
		updaterz.add(ma);
		
		ma=new ArrayMap<String,Object>();
		ma.put("vosin","•1.2.8");
		ma.put("message","社区发送帖子时可带图片\n新增回复评论消息提醒\n新增游戏王资讯\n点击图片可方法查看大图\n决斗房间和群聊显示其他用户到自己的距离\n在用户名片界面可以地图查看用户位置\n其他优化");
		updaterz.add(ma);
		
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.7");
			ma.put("message","新增“决斗”\n查找周围决斗者可以列表显示\n用内置浏览器浏览网页时可调用其他浏览器打开\n权限汪在群聊中名字显示为红色\n修复社区加载更多失败的问题\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.6");
			ma.put("message","新增主界面摇一摇反馈\n由于服务器限制搜索主题改为输入全名搜索\n修复ygomobile和ygomex同时存在时应用主题错误的bug\n修复有多个公告时查看公告顺序错乱的bug\n其他优化");
			updaterz.add(ma);
		
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.5");
			ma.put("message","应用主题,替换卡表支持ygomex\n新增公告\n默认替换卡表更新为2016.10.1 OCG禁卡表\n其他优化");
			updaterz.add(ma);
		
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.4");
			ma.put("message","新增强制转屏\n新增捐赠\n下载主题后可直接应用\n表情数量增加\n查找周围决斗者距离增加为5w公里\n图片显示优化\n社区可识别超链接,复制文字\n修复部分机型头像更换失败的bug\n修复一直显示等待图片上传完毕的bug\n修复主题大小显示不准确的bug\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.32");
			ma.put("message","修复复制文字错误的bug\n新增删除聊天消息\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.31");
			ma.put("message","聊天新增技能:滑稽\n修复主题下载位置错误的bug\n其他优化");
			updaterz.add(ma);

			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.2");
			ma.put("message","新增群聊\n新增社区\n卡店新增地图显示\n在文件管理等地方选择压缩包的打开方式时可选择用我们的游戏王打开\n新增用户签名\n其他优化");
			updaterz.add(ma);

			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.1");
			ma.put("message","修复应用主题失败的bug\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.2.0");
			ma.put("message","用bug码成了全新界面\n新增ygomobile主题功能\n新增卡店位置功能\n链接ygo卡组管理\n链接Mose(游戏王卡片Diy)\n替换卡表可选择本地文件\n默认替换卡表更新为2016.4.1 OCG禁卡表\n战队提示列表可自定义\n修复解压中文乱码的问题\n不再支持Android4.0以下的设备\n所有账户重置\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.07");
			ma.put("message","由于服务器问题去除自动下载卡图/字体/卡组/数据库\n新增自定义解压目录\n其他优化");
			updaterz.add(ma);
				
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.06");
			ma.put("message","新增下载字体\n新增下载卡组(卡组为每个包的新卡)\n新增下载数据库\n新增输入卡密下载卡图\n修复由废话引起的bug(卡表替换问题)\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.05");
			ma.put("message","新增自动更新卡图\n卡表替换更新至2016.1.1禁卡表\n去除ygomobile更新的功能,缩小软件体积\n修复替换禁卡表时不能检测root权限的bug\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.04");
			ma.put("message","修复替换卡表失败的bug\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.03");
			ma.put("message","新增更新卡表（需root权限）");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.02");
			ma.put("message","修复发表图片闪退的bug\n修复分享闪退的bug\n其他优化");
			updaterz.add(ma);
		
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1.01");
			ma.put("message","修复不能使用图片的问题\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.1");
			ma.put("message","“ygo助手”改名为“我们的游戏王”\n新增发帖功能\n全新布局\n新增一堆bug\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.0.4");
			ma.put("message","新增排表功能\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.0.3");
			ma.put("message","新增新版本自动更新功能\n新增ygomobile即时数据更新");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.0.2");
			ma.put("message","修复解压时卡顿的问题\n修复解压时不显示进度的问题\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.0.1");
			ma.put("message","新增选择图包的功能\n修复各种bug\n其他优化");
			updaterz.add(ma);
			
			ma=new ArrayMap<String,Object>();
			ma.put("vosin","•1.0");
			ma.put("message","下载/打开ygo\n提供下载卡图地址\n一键解压卡图（废话）");
			updaterz.add(ma);
		}
		return updaterz;
	}

	public void cshToolbar(Toolbar toolbar,String s){
		toolbar.setTitle(s);
		final AppCompatActivity a=(AppCompatActivity) context;
		a.setSupportActionBar(toolbar);
		toolbar.setNavigationIcon(context.getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
		toolbar.setNavigationOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					a.finish();
					// TODO: Implement this method
				}
			});
	}
	
	Handler handler = new Handler(){

		@Override
		public void handleMessage(Message msg)
		{
			// TODO: Implement this method
			super.handleMessage(msg);
			switch(msg.what){
				case 1:
					dus.setToast("正在解压"+msg.obj.toString());		
					break;
				case 2:
					dus.dis();
					show("应用成功");
					break;
				case 3:
					dus.dis();
					show("应用失败"+msg.obj.toString());
					break;
				case 6:
					dus.dialogj(false,"","正在应用中,请稍等");
					break;
                case 7:
                   dus.dis();
                    show("主题应用成功,但背景解压失败\n可能是禁止了我们的内存写入权限所导致");
				case 8:
					Object[] oo= (Object[]) msg.obj;
				
					((ImageView)oo[0]).setImageBitmap((Bitmap)oo[1]);
					
					break;				
					
		}
		}
		
	};
	
	void jd(String s){
		Message m=new Message();
		m.obj=s;
		m.what=1;
		handler.sendMessage(m);
	}
	
	
	//清除glide缓存
     public void glideclear (){
		 Glide.get(context).clearMemory(); 	 
	 }
	 
	 //跳转帖子
	 public void tieziIntent(String id){
		 Intent intent =new Intent(context,SqPinglun.class);
		 //帖子id
		 intent.putExtra("id",id);
		 context.startActivity(intent); 
	 }
	 
	 
	 
	 public boolean isygo(){
		 
			 if(IntentUtil.getAppIntent(context,"cn.garymb.ygomobile") != null)
			 {
				 try
				 {
					 PackageInfo info = context.getPackageManager().getPackageInfo("cn.garymb.ygomobile", 0);
					 if(info.versionCode>300102||info.versionCode==300102){
						 return true;
					 }else{
						 show("YGOMobile版本过老,请下载最新版本");
						 DialogUtils du=DialogUtils.getdx(context);
						 du.dialogDygo();
					 }
				 }
				 catch (PackageManager.NameNotFoundException e)
				 {
					 show("获取决斗软件信息失败,原因为"+e);
				 }    
			 }else{
				isDownloadygo();
			 }			
		 return false;
		 
	 }
	 
	/****************
	 *
	 * 发起添加群流程。群号：HR工作室反馈、建议(523481824) 的 key 为： zv5xSt-Zu739mNbsBfZ9Qn_-esYqHaT9
	 * 调用 joinQQGroup(zv5xSt-Zu739mNbsBfZ9Qn_-esYqHaT9) 即可发起手Q客户端申请加群 HR工作室反馈、建议(523481824)
	 *
	 * @param key 由官网生成的key
	 * @return 返回true表示呼起手Q成功，返回fals表示呼起失败
	 ******************/
	public boolean joinQQGroup(String key) {
		Intent intent = new Intent();
		intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key));
		// 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
		try {
			context.startActivity(intent);
			return true;
		} catch (Exception e) {
			// 未安装手Q或安装的版本不支持
			return false;
		}
	}
	
	//是否是新版本
	public static boolean getIsNewVersion()
	{
		String versionName=OurygoApplication.getContext().getResources().getString(R.string.version_name);
		SharedPreferences sh= OurygoApplication.getContext().getSharedPreferences("AppVersion", OurygoApplication.getContext().MODE_PRIVATE);
		String vn=sh.getString("versionName", "0");
		if (versionName.equals(vn))
		{
			return false;
		}else{
			sh.edit().putString("versionName", versionName).commit();
			return true;
		}
	}
	/*
	*检查文件夹是否存在,不存在则创建
	*path:文件夹路径
	*/
	public static void directoryCreate(String path){
		File f=new File(path);
		if(!f.exists()||!f.isDirectory()){
			f.mkdir();
		}
	}
	
	/*
	 *检查文件是否存在,不存在则创建
	 *path:文件路径
	 */
	public static void fileCreate(String path) throws IOException{
		File f=new File(path);
		if(!f.exists()){
				f.createNewFile();
		}
	}
	/*复制asseta文件夹里面的文件到指定文件夹
	 *name:文件名
	 **path:要复制到的文件夹
	 *
	 */
	public static void copyAssets(final String name,final String path) throws FileNotFoundException, IOException{

		//assets中文件名字
		String fileName = name;
		//拿到输入流
		InputStream in = OurygoApplication.getContext().getAssets().open(fileName);
		//打开输出流
		FileOutputStream out = new FileOutputStream(path+fileName);
		int len = -1 ;
		byte[] bytes = new byte[1024];
		//不断读取输入流
		while ((len = in.read(bytes)) != -1)
		{
			//写到输出流中
			out.write(bytes, 0, len);
		}
		out.close();
		in.close();
		
	}
	
	
	
	 public void isDownloadygo(){
		 final DialogUtils du=DialogUtils.getdx(context);
		 View[] vv= du.dialogt(false,"","未下载决斗软件呢,是否去下载呢？");
		 Button b1=(Button) vv[0];
		 Button b2=(Button) vv[1];
		 b1.setText("取消");
		 b2.setText("去吧");
		 b1.setOnClickListener(new OnClickListener(){

				 @Override
				 public void onClick(View p1)
				 {
					 du.dis();
					 // TODO: Implement this method
				 }
			 });
		 b2.setOnClickListener(new OnClickListener(){

				 @Override
				 public void onClick(View p1)
				 {
					 du.dis();
					 du.dialogDygo();
					 // TODO: Implement this method
				 }
			 });
		 
		 
	 }

	 //应用主题,path为主题绝对路径
	public void yyzt(final String path){
		//获取一个跳转到ygo的Intent
		Intent i1=IntentUtil.getAppIntent(context,"cn.garymb.ygomobile");
		if(i1!=null){
			//如果已安装ygo则解压主题
			yyzt(SharedPreferenceUtil.getYgopath(),path);
		}else{
			//否则提示安装ygo
			isDownloadygo();
		}
		
	 }
	 
	 private void yyzt(final String outPath,final String zipPath){
		 
		 new Thread(new Runnable(){
				 @Override
				 public void run()
				 {
					 //准备解压的dialog
					 handler.sendEmptyMessage(6);
					 try
					 {
						 //开始解压
						 unzip(new File(zipPath),outPath);
						 //解压成功
						 handler.sendEmptyMessage(2);
					 }
					 catch (Exception e)
					 {
						 //解压失败
						 Message hm=new Message();
						 hm.what=3;
						 hm.obj=e.toString();
						 handler.sendMessage(hm);
					 }
				 }
			 }).start();
	 }
	 
	 
	/*
	 *id:卡密
	 *ot:归属
	 *alias:同名卡
	 *setcode:字段
	 *type:卡片类型
	 *level:等级
	 *attribute:属性
	 *rece:种族
	 *atk:攻击力
	 *def:守备力
	 *category:效果类型
	 *name:卡名
	 *decs:效果
	 */

	public static List<Card> cardQuery(String name,SQLiteDatabase sjk)
	{
		List<Card> ca=new ArrayList<Card>();

		//SQLiteDatabase sjk=SQLiteDatabase.openOrCreateDatabase(CdbPath, null);//数据库不存在则创建，存在则取得对象的实例

		Cursor cu;
		if (!name.equals("")) {
			String where="";
			String where1="A.name in (select C.name from texts as C where C.name like ?)";
			String where2="A.id in (select C.id from texts as C where C.id like ?)";
			where = where1 + " or " + where2;
			cu = sjk.rawQuery("select B.id,ot,alias,setcode,type,level,attribute,race,atk,def,category,name,desc from texts as A left outer join datas as B on A.id =B.id where " + where
							  , new String[]{"%" + name + "%","%" + name + "%"});
		} else {
			cu = sjk.rawQuery("select d.id,ot,alias,setcode,type,level,attribute,race,atk,def,category,name,desc from datas d left join texts t on d.id=t.id", null);
		}
		if(cu.getCount()!=0){
			while(cu.moveToNext()){
				Card card=new Card();
				card.setId(cu.getString(0));
				card.setOt_16(cu.getString(1));
				card.setAlias(cu.getString(2));
				card.setSetcode_16(cu.getInt(3));
				card.setCard_type_16(cu.getInt(4));
				card.setLevel_16(cu.getInt(4), cu.getString(5));
				card.setAttribute_16(cu.getString(6));
				card.setRace_16(cu.getString(7));
				card.setAtk_16(cu.getInt(4), cu.getString(8));
				card.setDef_16(cu.getInt(4), cu.getString(9));
				card.setName(cu.getString(11));
				card.setDesc(cu.getString(12));
				ca.add(card);
			}
		}
		cu.close();

		return ca;
	}
	 
	/*
	 *id:卡密
	 *ot:归属
	 *alias:同名卡
	 *setcode:字段
	 *type:卡片类型
	 *level:等级
	 *attribute:属性
	 *rece:种族
	 *atk:攻击力
	 *def:守备力
	 *category:效果类型
	 *name:卡名
	 *decs:效果
	 */
	 
	public static List<Card> cardQuery(String name)
	{
		List<Card> ca=new ArrayList<Card>();

		SQLiteDatabase sjk=SQLiteDatabase.openOrCreateDatabase(SharedPreferenceUtil.getCdbpath(), null);//数据库不存在则创建，存在则取得对象的实例
		
		Cursor cu;
		if (!name.equals("")) {
			String where="";
			String where1="A.name in (select C.name from texts as C where C.name like ?)";
			String where2="A.id in (select C.id from texts as C where C.id like ?)";
			where = where1 + " or " + where2;
			cu = sjk.rawQuery("select B.id,ot,alias,setcode,type,level,attribute,race,atk,def,category,name,desc from texts as A left outer join datas as B on A.id =B.id where " + where
							  , new String[]{"%" + name + "%","%" + name + "%"});
		} else {
			cu = sjk.rawQuery("select d.id,ot,alias,setcode,type,level,attribute,race,atk,def,category,name,desc from datas d left join texts t on d.id=t.id", null);
		}
		if(cu.getCount()!=0){
			while(cu.moveToNext()){
				Card card=new Card();
				card.setId(cu.getString(0));
				card.setOt_16(cu.getString(1));
				card.setAlias(cu.getString(2));
				card.setSetcode_16(cu.getInt(3));
				card.setCard_type_16(cu.getInt(4));
				card.setLevel_16(cu.getInt(4), cu.getString(5));
				card.setAttribute_16(cu.getString(6));
				card.setRace_16(cu.getString(7));
				card.setAtk_16(cu.getInt(4), cu.getString(8));
				card.setDef_16(cu.getInt(4), cu.getString(9));
				card.setName(cu.getString(11));
				card.setDesc(cu.getString(12));
				ca.add(card);
			}
		}
		cu.close();

		return ca;
	}
	 
	/*
	 * @param file      待解压文件
	 * @param dir       解压后文件的存放目录
	 * @throws IOException
	 */
	public void unzip(File file, String dir) throws IOException {
		ZipFile zipFile = new ZipFile(file, "GBK");//设置压缩文件的编码方式为GBK
		Enumeration<ZipEntry> entris = zipFile.getEntries();
		ZipEntry zipEntry = null;
		File tmpFile = null;
		BufferedOutputStream bos = null;
		InputStream is = null;
		byte[] buf = new byte[1024];
		int len = 0;

		while (entris.hasMoreElements()) {
			zipEntry = entris.nextElement();
			// 不进行文件夹的处理,些为特殊处理
			tmpFile = new File(dir + zipEntry.getName());
			//显示解压目录
			jd(dir + zipEntry.getName());
			
			if (zipEntry.isDirectory()) {//当前文件为目录
				if (!tmpFile.exists()) {
					tmpFile.mkdir();
				}
			} else {
				if (!tmpFile.exists()) {
					tmpFile.createNewFile();
				}
				is = zipFile.getInputStream(zipEntry);
				bos = new BufferedOutputStream(new FileOutputStream(tmpFile));
				while ((len = is.read(buf)) > 0) {
					bos.write(buf, 0, len);
				}
				bos.flush();
				bos.close();

			}
		}
	}
	
	 //判断服务是否开启,classname为服务名
	public boolean isservicerun(String className) {
		ActivityManager myManager = (ActivityManager) context
			.getApplicationContext().getSystemService(
			Context.ACTIVITY_SERVICE);
		ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager
			.getRunningServices(30);
		for (int i = 0; i < runningService.size(); i++) {
			if (runningService.get(i).service.getClassName().toString()
				.equals(className)) {
				return true;
			}
		}
		return false;
	}
	
	//获取指定网址的json数据并返回
	public static JSONObject getUriJson(String strUrl)
	{  
		// HttpGet对象  
		HttpGet httpRequest = new HttpGet(strUrl);  
		String strResult = null;  
		try
		{  
			// HttpClient对象  
			HttpClient httpClient = new DefaultHttpClient();  
			// 获得HttpResponse对象  
			HttpResponse httpResponse = httpClient.execute(httpRequest);  
	
			if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
			{  
				// 取得返回的数据  
				strResult = EntityUtils.toString(httpResponse.getEntity());  
			}  
			return new JSONObject(strResult);
		}
		catch (Exception e)
		{  
			return null;
		}  
	}  
	
	/*
	*字节转可读大小
	*fileSize:文件字节大小
	*/
	public String fileDx(int fileSize){
		//文件大小
		String dx="0M";
		int ddx1=fileSize/1024/1024;
		if(ddx1<1){
			dx=fileSize/1024%1024+"K";
		}else {
			String iii=fileSize/1024%1024+"";
			switch(iii.length()){
				case 1:
					iii="00"+iii;
					break;
				case 2:
					iii="0"+iii;
					break;
			}
			dx=ddx1+"."+iii+"M";
		}
		return dx;
	}
	
	
	//检查主题,如果为""则是正常的,否则有问题
	public String ztJiancha(String zipPath){
		String cath="";
		try
		{
			java.util.zip.ZipFile zip=new java.util.zip.ZipFile(zipPath);
			if(zip!=null){
				java.util.zip.ZipEntry ze=zip.getEntry("textures/");
				if(ze!=null&&ze.isDirectory()){
					for(String ss:ZHUTI_TEXTURES){
						java.util.zip.ZipEntry zy=zip.getEntry("textures/"+ss);
						if(zy==null){
							cath+=ss+"\n";
						}
					}
					if(!cath.equals("")){
						cath="以下文件不存在\n"+cath;
					}
					String ff="";
					Enumeration<java.util.zip. ZipEntry> entris =  (Enumeration<java.util.zip.ZipEntry>) zip.entries();		
					while (entris.hasMoreElements()) {
						String name = entris.nextElement().getName();
						boolean bb=false;
						for(String ss:ZHUTI_TEXTURES){
							if(name.equals("textures/")||name.equals("textures/"+ss)){
								bb=true;
								break;
							}	
						}
						if(!bb){
							ff+=name+"\n";
						}		
					}
					
					if(!ff.equals("")){
						ff="\n以下为多余文件\n"+ff;
					}
					cath+=ff;
					
				}else{
					cath="主题包最外层文件夹不是textures";
				}
			}else{
				cath="未找到该主题包";
			}

		}catch (IOException e){
			cath="读取压缩包失败,原因为"+e;
		}
		return cath;
	}
	
	
				
	//返回本地json文件数据
	public static JSONObject getlocalJson(String path) throws FileNotFoundException, IOException, JSONException
	{
			InputStream is =new FileInputStream(path);
			//this.getResources().openRawResource(R.raw.json);
			byte[] buffer = new byte[is.available()];
			is.read(buffer);
			//将字节数组转换为以UTF-8编码的字符串
			String json = new String(buffer, "UTF-8");
			//将字符串json转换为json对象，以便于取出数据
			JSONObject jsonObject = new JSONObject(json);

			return jsonObject;

	}
	
	
	
	public static final RequestOptions glideOption =RequestOptions
								.diskCacheStrategyOf(DiskCacheStrategy.ALL)
								.skipMemoryCache(true)
								.placeholder(R.drawable.image_jiazai);
								
	public static final RequestOptions glideOption1 =RequestOptions
	.diskCacheStrategyOf(DiskCacheStrategy.ALL)
	.skipMemoryCache(true)
	.placeholder(R.drawable.unknown);
	
	public static ISListConfig getPicConfig(int num){
		boolean dx=false;
		if(num>1)
			dx=true;
		// 自由配置选项
		ISListConfig config = new ISListConfig.Builder()
			// 是否多选, 默认true
			.multiSelect(dx)
			// 是否记住上次选中记录, 仅当multiSelect为true的时候配置，默认为true
			.rememberSelected(false)
			// “确定”按钮背景色
			.btnBgColor(Color.parseColor("#ffdb868b"))
			// “确定”按钮文字颜色
			.btnTextColor(Color.WHITE)
			// 使用沉浸式状态栏
			.statusBarColor(OurygoApplication.getContext().getResources().getColor( R.color.colorMain))
			// 返回图标ResId
			.backResId(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_mtrl_am_alpha)
			// 标题
			.title("图片选择")
			// 标题文字颜色
			.titleColor(Color.WHITE)
			// TitleBar背景色
			.titleBgColor(OurygoApplication.getContext().getResources().getColor( R.color.colorMain))

			// 第一个是否显示相机，默认true
			.needCamera(true)
			// 最大选择图片数量，默认9
			.maxNum(num)
			.build();
			return config;
	}
	
	
	
	public void getPicConfig(){
		// 自定义图片加载器
		ISNav.getInstance().init(new ImageLoader() {
				@Override
				public void displayImage(Context context, String path, ImageView imageView) {
					Glide.with(context).load(path).into(imageView);
				}
			});
	}
	
	public void tuxian(String uri,final ImageView im/*,int height,int width*/){
		//判断哪些网络显示图片
		switch(SharedPreferenceUtil.getImageXs()){
			case SharedPreferenceUtil.IMAGE_ALL:
				
				break;
			case SharedPreferenceUtil.IMAGE_NO:
				
				return;
			case SharedPreferenceUtil.IMAGE_WIFI:
				
				break;
		}
        if(uri!=null){
			
            Glide.with(context)
                .load(Uri.parse(uri))
                .apply(glideOption)
                .into(im);
        }
    }
	
    public void tuxian(BmobFile bf,final ImageView im){
        
       if(bf!=null){
            tuxian(bf.getFileUrl(),im);
        }
    }
	
	public void setAvatar(BmobFile bf,final ImageView im){

		if(bf!=null){
            tuxian(bf.getFileUrl(),im);
        }
    }
	public void setAvatar(String uri, final ImageView im) {
		//判断哪些网络显示图片
		switch (SharedPreferenceUtil.getImageXs()) {
			case SharedPreferenceUtil.IMAGE_ALL:
				break;
			case SharedPreferenceUtil.IMAGE_NO:
				return;
			case SharedPreferenceUtil.IMAGE_WIFI:

				break;
		}
        if (uri != null) {
            Glide.with(context)
				.asBitmap()
                .load(Uri.parse(uri))
                .apply(glideOption)
                .into(im);
        }
    }
	
	
	public void checkUpdate(final boolean b){
		final DialogUtils du=DialogUtils.getdx(context);
		Activity a=(Activity) context;
		
		
		//蒲公英自动检查更新
		PgyUpdateManager.register(a,
			new UpdateManagerListener() {

				@Override
				public void onUpdateAvailable(final String result) {
					final String versionName,updateMessage,downloadUrl;
					// 将新版本信息封装到AppBean中
					final AppBean appBean = getAppBeanFromString(result);
					versionName=appBean.getVersionName();
					updateMessage=appBean.getReleaseNote();
					downloadUrl=appBean.getDownloadURL();
					View[] vv=du.dialogAppUpdate(versionName,updateMessage);
					Button b1,b2;
					b1=(Button) vv[0];
					b2=(Button) vv[1];
					b1.setText("取消");
					b2.setText("更新");
					b1.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								du.dis();
								// TODO: Implement this method
							}
						});
					b2.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(final View vi)
							{
								du.dis();
								View[] v=du.dialogj1(false,"","准备下载,请稍等");

								final TextView t=(TextView) v[0];
								String filename="";

								filename="我们的游戏王-"+versionName+".apk";
								BmobFile bf=new BmobFile(filename,"",downloadUrl);
								bf.download(new File(PATH_OURYGO+"download/"+filename), new DownloadFileListener(){

										@Override
										public void done(String p1, BmobException p2)
										{
											if(p2==null){
												du.dis();
												UpdateManagerListener.updateLocalBuildNumber(result);
												Intent in=IntentUtil.getApkFileIntent(context,p1);
												if(in!=null){
													context.startActivity(in);
												}

											}else{
												du.dis();
												toastBmobException(vi,"下载失败",p2);
												//show("下载失败,原因为"+p2);
											}
											// TODO: Implement this method
										}

										@Override
										public void onProgress(Integer p1, long p2)
										{
											t.setText("正在下载"+p1+"%");
											// TODO: Implement this method
										}
									});
								// TODO: Implement this method
							}
						});
				}

				@Override
				public void onNoUpdateAvailable() {

					if(b){
					show("新版本还没做好呢(๑• . •๑)");
					}

				}
			});
		
	}
	
	/*
	*设置用户头像
	*image:头像图片
	*mu:用户对象
	*height:头像高
	*width:头像宽
	*/
	public String  setTouxiang(final ImageView image,MyUser mu){
		
		String u="";
		image.setBackgroundColor(android.R.color.transparent);
		if(mu!=null){
		BmobFile tx=mu.getavatar();
		if(tx!=null){
			setAvatar(tx.getFileUrl(),image);
			u= tx.getFileUrl();
		}else{
			String email=mu.getEmail();
			if(email.indexOf("@qq.com")!=-1){
				String qq=email.substring(0,email.indexOf("@qq.com"));
				String txurl="http://q1.qlogo.cn/g?b=qq&nk="+qq+"&s=100&t=999";
				setAvatar(txurl,image);
				u=txurl;
			}else{
				image.setImageResource(R.drawable.lt_tx);
			}
		}
		}else{
			image.setImageResource(R.drawable.lt_tx);
		}
		return u;
	}
	
	/**
	 * 分享图片和文字内容
	 * 
	 * @param dlgTitle
	 *            分享对话框标题
	 * @param subject
	 *            主题
	 * @param content
	 *            分享内容（文字）
	 * @param uri
	 *            图片资源URI
	 */
	public void ydkfx(String dlgTitle, String subject, String s, Uri uri)
	{
		if (uri == null)
		{
			return;
		}
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("image/jpg");
		intent.putExtra(Intent.EXTRA_STREAM, uri);
		if (subject != null && !"".equals(subject))
		{
			intent.putExtra(Intent.EXTRA_SUBJECT, subject);
		}
		if (s != null && !"".equals(s))
		{
			intent.putExtra(Intent.EXTRA_TEXT, s);
		}

		// 设置弹出框标题
		if (dlgTitle != null && !"".equals(dlgTitle))
		{ // 自定义标题
			context.startActivity(Intent.createChooser(intent, dlgTitle));
		}
		else 
		{ // 系统默认标题
			context.startActivity(intent);
		}
	}
	
	//提示
	public static void show(String s){
		Toast.makeText(OurygoApplication.getContext(),s,Toast.LENGTH_SHORT).show();
	}

	/*
	*四舍五入小数
	*d:小数
	*w:保留小数位数
	*
	*/
	public double formatDouble(double d,int w){
		BigDecimal b = new BigDecimal(d);  
		return b.setScale(w, BigDecimal.ROUND_HALF_UP).doubleValue();  
	}
	
	
	//复制字符串到剪贴板
	public void fzMessage(String s){	
		ClipboardManager cmb = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE);
		cmb.setText(s);//复制命令
		
	}
	
	//隐藏虚拟键盘
	public static void HideKeyboard(View v)
	{
		InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );     
        if ( imm.isActive( ) ) {     
            imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) , 0 );   

        }    
	}
 // 显示输入法
	public static void showInputMethod(View view,Context context) {
		InputMethodManager inputMethodManager = (InputMethodManager) context.getApplicationContext()
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		//同时再使用该方法之前，view需要获得焦点，可以通过requestFocus()方法来设定。
		view.requestFocus();
		inputMethodManager.showSoftInput(view, inputMethodManager.SHOW_FORCED);
	}
	
	
	//显示虚拟键盘
	public static void ShowKeyboard(View v)
	{
		InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );     

        imm.showSoftInput(v,InputMethodManager.SHOW_FORCED);    

	}
	//关闭输入法
	public  void closeKeyboard(){
		InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
		inputMethodManager.hideSoftInputFromWindow(((Activity)context).getCurrentFocus().getWindowToken()
												   ,InputMethodManager.HIDE_NOT_ALWAYS);
	}
	
	
	private static final String[] jzlist={
		"呵","傻","垃圾"
	};
	
	public static boolean isfs(String s){
		for(String ss:jzlist){
		if(s.indexOf(ss)!=-1){
			return false;
			}
		}
		return true;
	}
	
	/*
	 *获取脚本
	 *km:卡密
	 */
	public static String getjb(String km){
		String jb="";
		try{
		File ff=new File(SharedPreferenceUtil.getYgopath() + "script/c" + km + ".lua");
		if (ff.exists())
		{
			BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(ff)));
			String line="";

			for (;(line = reader.readLine()) != null;)
			{
				jb += line +"\n";
			}
			}else{
		
				java.util.zip.ZipFile zip=new java.util.zip.ZipFile(SharedPreferenceUtil.getYgopath() + "scripts.zip");
				if (zip != null)
				{
					java.util.zip.ZipEntry ze=zip.getEntry("script/c" + km + ".lua");
					if (ze != null)
					{				
						BufferedReader reader=new BufferedReader(new InputStreamReader(zip.getInputStream(ze)));
						String line="";
						for (;(line = reader.readLine()) != null;)
						{
							jb += line +"\n";
						}
					}else{
						show("压缩包为空");
					}
				}
			}
		}catch (IOException e){
				Log.e("读取错误","原因为"+e);
		}
		return jb;
	}
	static java.util.zip.ZipFile zip;
	
	
	public  static void setKt(Context context,ImageView im,String km){
		if(zip==null){
			try
			{
				zip = new java.util.zip.ZipFile(SharedPreferenceUtil.getYgopath() + "pics.zip");
			}catch (IOException e){
				Glide.with(context)
				.asBitmap()
					.load(R.drawable.unknown) 
					.apply(glideOption1)
					.into(im);
			}
		}
		
		if(km!=null&&!km.equals("")){
			File ff=new File(SharedPreferenceUtil.getYgopath() + "pics/" + km + ".jpg");
			if (ff.exists())
			{
				Glide.with(context)
					.load(SharedPreferenceUtil.getYgopath() + "pics/" + km + ".jpg") 
					.apply(glideOption1)
					.into(im);
			}else{
				try{
					if (zip != null)
					{
						java.util.zip.ZipEntry ze=zip.getEntry("pics/" + km + ".jpg");
						if (ze != null)
						{
							ByteArrayOutputStream outs = new ByteArrayOutputStream();
							InputStream input = zip.getInputStream(ze);
							copy(input,outs);
							Glide.with(context)
							.asBitmap()
								.load(outs.toByteArray()) 
								.apply(glideOption1)
								.into(im);
						}
					}

				}
				catch (IOException e)
				{
				}
			}
		}else{
			Glide.with(context)
			.asBitmap()
                .load(R.drawable.unknown) 
                .apply(glideOption1)
			 	.into(im);
		}
		
	}
	
	
	public static void copy(InputStream in, OutputStream out) throws IOException {
        byte[] cache = new byte[1024 * 8];
        int len;
        while ((len = in.read(cache)) != -1) {
            out.write(cache, 0, len);
        }
    }
	{}
	
	
	/*
	*获取卡图
	*km:卡密
	*/
	public static Bitmap getkt1(String km)
	{
		Bitmap bt= BitmapFactory.decodeResource(OurygoApplication.getContext().getResources(), R.drawable.unknown);
		
		if(zip==null){
			try
			{
				zip = new java.util.zip.ZipFile(SharedPreferenceUtil.getYgopath() + "pics.zip");
			}catch (IOException e){
				return bt;
			}
		}
			if(km!=null&&!km.equals("")){
		File ff=new File(SharedPreferenceUtil.getYgopath() + "pics/" + km + ".jpg");
		if (ff.exists()){
			bt = BitmapFactory.decodeFile(SharedPreferenceUtil.getYgopath() + "pics/" + km + ".jpg");
		}else{
			try{
			if (zip != null){
					java.util.zip.ZipEntry ze=zip.getEntry("pics/" + km + ".jpg");
					if (ze != null){
						bt = new BitmapDrawable(zip.getInputStream(ze)).getBitmap();
					}
				}
			}catch (IOException e){
			}
		}
		}
		return bt;
	}
	
	
	//获取更新包解压路径
	public static String getJypath(String zipPath){
		String path = SharedPreferenceUtil.getYgopath();	
		try
		{
			//获取压缩包对象
			ZipFile zipfile=new ZipFile(zipPath);
			//获取压缩包内所有文件
			Enumeration<ZipEntry> ze=zipfile.getEntries();
			//遍历文件
			while (ze.hasMoreElements()) {
				ZipEntry entry = ze.nextElement();
				//如果是文件夹
				if(entry.isDirectory()){
					//获取其名称,判断最前面的目录是否为ygocore,如果是则解压到ygo资源目录父目录,否则解压到ygo资源目录中
					String name=entry.getName();
					String[] ss=name.split("/");
						if(ss[0].equals("ygocore")){
							String[] ss1=SharedPreferenceUtil.getYgopath().split("/");
							path="";
							for(int i=0;i<ss1.length-1;i++){
								path=path+ss1[i]+"/";
							}
							return path;
						}else{
						return path;
					}				
				}
			}
		}catch (IOException e){
		
		}
		return path;
	}
	
	
	// 保存到sdcard
    public static String saveBitmap(Bitmap b, String savePath, String name) throws FileNotFoundException, IOException {

        FileOutputStream fos = null;
		File f = new File(savePath, name + ".jpg");
		if (f.exists()) {
			f.delete();
		}

		fos = new FileOutputStream(f);
		b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
		fos.flush();
		fos.close();
		return savePath + name + ".jpg";
    }
	
	public static String jsonBmobException(BmobException e){
		String er;
		switch(e.getErrorCode()){
			case 9001:
				er="应用信息初始化失败";
				break;
			case 9002:
				er="解析返回数据出错";
				break;
			case 9003:
				er="上传文件出错";
				break;
			case 9004:
				er="文件上传失败";
				break;
			case 9005:
				er="批量操作只支持最多50条";
				break;
			case 9006:
				er="信息id为空";
				break;
			case 9007:
				er="文件大小超过10M";
				break;
			case 9008:
				er="上传文件不存在";
				break;
			case 9009:
				er="没有缓存数据";
				break;
			case 9010:
				er="网络超时";
				break;
			case 9011:
				er="用户信息不能批量操作";
				break;
			case 9012:
				er="上下文为空";
				break;
			case 9013:
				er="（数据表名称）格式不正确";
				break;
			case 9014:
				er="第三方账号授权失败";
				break;
			case 9015:
				er="本地错误";
				break;
			case 9016:
				er="没有网络连接呢,请检查喵的手机网络";
				break;
			case 9017:
				er="第三方帐号登录失败";
				break;
			case 9018:
				er="参数不能为空";
				break;
			case 9019:
				er="手机号码/邮箱地址/验证码格式不正确";
				break;
			case 9020:
				er="保存CDN信息失败";
				break;
			case 9021:
				er="文件上传缺少wakelock权限";
				break;
			case 9022:
				er="文件上传失败，请重新上传";
				break;
			case 9023:
				er="应用信息未初始化";
				break;
			case 9024:
				er="请确认喵已经登录";
				break;
			default:
			er="未知错误";
			break;
		}
		er+="\n("+e.getMessage()+")";
		return er;
	}
	
	
	//以Sanckbar提示bmob的错误
	public  void toastBmobException(View v,final String toast,final BmobException e){
		SnackbarUtil.ShortSnackbar(v,toast,SnackbarUtil.white,SnackbarUtil.red)
			.setActionTextColor(Color.parseColor("#000000")).setAction("查看原因", new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					final String ex=jsonBmobException(e);
					View[] v1=dus.dialogt1(true,toast,ex);
					Button b1=(Button) v1[0];
					b1.setText("复制错误原因");
					b1.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								fzMessage(ex);
								dus.dis();
								// TODO: Implement this method
							}
						});
					// TODO: Implement this method
				}
			}).show();
	}

	
}

	
